import { EnumSchema } from '@/utils/common/types';
import { PresetColorEnum } from '@/enums/colorEnum';
import { useI18n } from '@/hooks/web/useI18n';

/** 数据库对象类型枚举 */
export enum DatabaseObjectTypeEnum {
  /** 数据表 */
  Table = 1,
  /** 数据视图 */
  View = 2,
  /** 函数 */
  Function = 3,
  /** 存储过程 */
  Procedure = 4,
  /** 触发器 */
  Trigger = 5,
}

/** 数据库对象类型实体 */
export class DatabaseObjectTypeEntity {
  /** 数据库对象类型 */
  DatabaseObjectType: DatabaseObjectTypeEnum;
  /** 显示描述 */
  Display: string;
  /** 颜色 */
  Color?: PresetColorEnum | string;

  constructor(databaseObjectType: DatabaseObjectTypeEnum, color?: PresetColorEnum | string) {
    const { t } = useI18n();
    this.DatabaseObjectType = databaseObjectType;
    this.Color = color;
    switch (databaseObjectType) {
      case DatabaseObjectTypeEnum.Table:
        // this.Display = '数据表';
        this.Display = t('enum.databaseObjectType.table');
        this.Color = this.Color ? this.Color : PresetColorEnum.Blue;
        break;
      case DatabaseObjectTypeEnum.View:
        // this.Display = '数据视图';
        this.Display = t('enum.databaseObjectType.view');
        this.Color = this.Color ? this.Color : PresetColorEnum.Orange;
        break;
      case DatabaseObjectTypeEnum.Function:
        // this.Display = '函数';
        this.Display = t('enum.databaseObjectType.function');
        this.Color = this.Color ? this.Color : PresetColorEnum.Green;
        break;
      case DatabaseObjectTypeEnum.Procedure:
        // this.Display = '存储过程';
        this.Display = t('enum.databaseObjectType.procedure');
        this.Color = this.Color ? this.Color : PresetColorEnum.Lime;
        break;
      case DatabaseObjectTypeEnum.Trigger:
        // this.Display = '触发器';
        this.Display = t('enum.databaseObjectType.trigger');
        this.Color = this.Color ? this.Color : PresetColorEnum.Red;
        break;
    }
  }
}

//#region 获取数据库对象类型枚举架构
/**
 * 获取数据库对象类型枚举架构
 */
export function getDatabaseObjectTypeEnumSchema(enableTag = true): EnumSchema[] {
  const enumSchema: EnumSchema[] = [];
  const entities: DatabaseObjectTypeEntity[] = [
    new DatabaseObjectTypeEntity(DatabaseObjectTypeEnum.Table),
    new DatabaseObjectTypeEntity(DatabaseObjectTypeEnum.View),
    new DatabaseObjectTypeEntity(DatabaseObjectTypeEnum.Function),
    new DatabaseObjectTypeEntity(DatabaseObjectTypeEnum.Procedure),
    new DatabaseObjectTypeEntity(DatabaseObjectTypeEnum.Trigger),
  ];
  entities.forEach((item) => {
    enumSchema.push({
      key: item.DatabaseObjectType as number,
      label: item.Display,
      value: item.DatabaseObjectType as number,
      tag: enableTag,
      tagColor: item.Color,
    });
  });
  return enumSchema;
}
//#endregion
